<?php
/**
 * Created by PhpStorm.
 * User: Sergey
 * Date: 16.03.14
 * Time: 18:26
 */

require_once BASE_DQ_PLUGIN_PATH . "classes/GroupDao.php";
$groupDao = new GroupDao();

if (isset($_GET["action"]) && $_GET["action"] == "remove"
    && isset($_GET["id"])
) {
    $groupDao->remove(intval($_GET["id"]));
    header(
        "Location: " . menu_page_url("distant-quiz/admin.php", false) .
        "#groups"
    );
}

$groups = $groupDao->getAll();
?>

<a href="<?= menu_page_url("distant-quiz/group-form.php", false) ?>"
   class="jquery-button">
    Добавить группу
</a>
<br>
<br>
<table class="wp-list-table widefat fixed posts">
    <thead>
    <tr>
        <th>Id</th>
        <th>Название</th>
        <th>Кол-во студентов</th>
        <th>Операции</th>
    </tr>
    </thead>

    <tbody>
    <? foreach ($groups as $group) { ?>
        <tr>
            <td><?= $group->id ?></td>
            <td><?= $group->name ?></td>
            <td><?= 10 ?></td>
            <td>
                <a href="<?=
                menu_page_url("distant-quiz/group-form.php", false) .
                "&id=" . $group->id
                ?>"
                   class="jquery-button">Редактировать</a>
                <a href="<?=
                menu_page_url("distant-quiz/admin.php", false) .
                "&action=remove&id=" . $group->id
                ?>"
                   class="jquery-button">Удалить</a>
            </td>
        </tr>
    <? } ?>
    </tbody>
</table>